home *** CD-ROM | disk | FTP | other *** search
-
-
- /************************************************************************/
- /* hpclip.c */
- /************************************************************************/
- #define NOCOMM
-
- #include "windows.h"
- #include "hpclip.h"
- #include <stdio.h>
- #include <string.h> /* for strtok */
-
- /* Modules */
- int PASCAL WinMain(HANDLE,HANDLE,LPSTR,int);
- long FAR PASCAL DemoWndProc(HWND,unsigned,WORD,LONG);
- VOID DemoPaint(HWND);
- VOID Print(HWND);
- VOID DrawFilledArea(HWND,HDC);
- VOID FAR PASCAL ShadeXProc(short,short,LPSTR);
-
- /* Globals */
- char szAppName[10] = "HPCLIP";
- char szMessage[60] = "Demonstrate Setting Cliping Region" ;
- HANDLE hInst;
- HANDLE hLibrary;
- HDC hShadeDC;
- POINT ptShadeLength;
-
- /*************************************************************************/
- int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
- HANDLE hInstance, hPrevInstance;
- LPSTR lpszCmdLine;
- int cmdShow;
- {
- MSG msg;
- HWND hWnd;
- WNDCLASS wndclass;
-
- if (!hPrevInstance)
- {
- wndclass.style = CS_HREDRAW | CS_VREDRAW;
- wndclass.lpfnWndProc = DemoWndProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInstance;
- wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
- wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
- wndclass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
- wndclass.lpszMenuName = "DemoMenu";
- wndclass.lpszClassName = (LPSTR)szAppName;
-
- if (!RegisterClass(&wndclass))
- return FALSE;
- }
-
- hWnd = CreateWindow((LPSTR)szAppName,(LPSTR)szMessage,
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,
- hInstance,NULL);
-
- hInst = hInstance;
-
- ShowWindow(hWnd,cmdShow);
- UpdateWindow(hWnd);
-
- while (GetMessage(&msg,NULL,0,0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- return (int)msg.wParam;
- }
-
- /************************************************************************/
- long FAR PASCAL DemoWndProc(hWnd,message,wParam,lParam)
- HWND hWnd;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
-
- switch (message)
- {
-
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
- case WM_COMMAND:
- switch(wParam)
- {
- case ID_PRINT:
- Print(hWnd);
- break;
-
- default:
- return DefWindowProc(hWnd,message,wParam,lParam );
- break;
- }
- break;
-
- case WM_PAINT:
- DemoPaint(hWnd);
- break;
-
- default:
- return DefWindowProc( hWnd, message, wParam, lParam );
- break;
- }
- return(0L);
- }
-
- /************************************************************************/
- VOID Print(hWnd)
- HWND hWnd;
- {
- HDC hPrinterDC;
- char szDefaultDevice[80];
- PSTR spDefaultDeviceName,spPort,spFileName;
- int iLength;
- HCURSOR hOldCursor ;
-
- hOldCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)) ;
-
- /* Use the default printer. */
- iLength = GetProfileString("windows","device",(LPSTR)"",szDefaultDevice,80);
- spDefaultDeviceName = strtok(szDefaultDevice,",");
- spFileName = strtok(NULL,", ");
- spPort = strtok(NULL,", ");
-
- /* Get a display context. */
- hPrinterDC = CreateDC((LPSTR)spFileName,(LPSTR)spDefaultDeviceName,
- (LPSTR)spPort,(LPSTR)NULL);
-
- Escape(hPrinterDC,STARTDOC,4,"HPCLIP",(LPSTR)NULL);
-
- SetMapMode(hPrinterDC,MM_LOENGLISH);
-
- DrawFilledArea(hWnd,hPrinterDC);
-
- Escape(hPrinterDC,NEWFRAME,0,(LPSTR)NULL,(LPSTR)NULL);
- Escape(hPrinterDC,ENDDOC,NULL,(LPSTR)NULL,(LPSTR)NULL);
-
- DeleteDC(hPrinterDC);
-
- SetCursor (hOldCursor) ;
- MessageBeep (0) ;
- }
-
- /************************************************************************/
- /* DRAW FILLED AREA */
- /************************************************************************/
-
- VOID DrawFilledArea(hWnd,hDC)
- HWND hWnd;
- HDC hDC;
- {
- HRGN hFrontRgn;
- FARPROC lpProcAddress;
- RECT rcRect;
- POINT pt;
- HPEN hOldPen ;
- HBRUSH hOldBrush ;
- char szStr[20] ;
-
- TextOut(hDC,50,-50,"A circle filled with lines should appear below. ",48);
-
- /* Form the area in logical coordinates. */
- rcRect.left = 100;
- rcRect.top = -100;
- rcRect.right = 200;
- rcRect.bottom = -200;
-
- SelectObject (hDC, GetStockObject (NULL_BRUSH)) ;
- /* Convert these to device coordinates. */
- LPtoDP(hDC,(LPPOINT)&rcRect,2);
-
-
- /* adjust the coordinates using the scaling factors */
-
- pt.x = pt.y = 0;
- Escape(hDC,GETSCALINGFACTOR,0,NULL,(LPSTR)&pt);
- rcRect.left >>= pt.x;
- rcRect.right >>= pt.x;
- rcRect.top >>= pt.y;
- rcRect.bottom >>= pt.y;
-
- // Create an elliptical region to fill in with lines.
- hFrontRgn = CreateEllipticRgn(rcRect.left,rcRect.top,
- rcRect.right,rcRect.bottom);
-
- // Put this clipping region into the display context.
- SelectClipRgn(hDC,hFrontRgn);
-
- // We pass the global variable to the call back procedure ShadeXProc.
- hShadeDC = hDC;
-
- // Make the call back function.
- lpProcAddress = MakeProcInstance(ShadeXProc,hInst);
-
- ptShadeLength.x = 100;
-
- // We draw horizontal lines to fill in the area. Works on plotters and printers
- LineDDA(100,-100,100, -200,(FARPROC)lpProcAddress,(LPSTR)NULL);
-
- FreeProcInstance(lpProcAddress);
- DeleteObject (hFrontRgn) ;
-
- }
-
- /************************************************************************/
- /* DEMO PAINT */
- /************************************************************************/
-
- VOID DemoPaint(hWnd)
- HWND hWnd;
- {
- HDC hDC;
- PAINTSTRUCT ps;
-
- hDC = BeginPaint(hWnd,&ps);
- SetMapMode(hDC,MM_LOENGLISH);
-
- DrawFilledArea(hWnd,hDC);
-
- EndPaint(hWnd,&ps);
- }
-
- /************************************************************************/
- /* SHADE X PROC */
- /************************************************************************/
-
- /*
- ** This module draws a horizontal line for each point it is given.
- */
-
- VOID FAR PASCAL ShadeXProc(x,y,lpData)
- short x;
- short y;
- LPSTR lpData;
- {
- MoveTo(hShadeDC,x,y);
- LineTo(hShadeDC,x+ptShadeLength.x,y);
- }
-
-